<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Validation\ValidationException as LaravelValidationException;

class ValidationException extends Exception
{
    protected $errors;

    public function __construct(string $message = '数据验证失败', $errors = [])
    {
        parent::__construct($message, 422);
        $this->errors = $errors;
    }

    public function getErrors()
    {
        return $this->errors;
    }

    public static function fromLaravelValidation(LaravelValidationException $exception): self
    {
        return new self(
            '数据验证失败',
            $exception->errors()
        );
    }
}
